using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using UwinEducation.API.Attributes;
using UwinEducation.Application.Common.Interfaces;
using UwinEducation.Application.Dtos;
using UwinEducation.Shared.Models;

namespace UwinEducation.API.Controllers
{
    /// <summary>
    /// 教室管理控制器
    /// </summary>
    [Authorize]
    //[RequirePermission("basic.classroom")] // 指定所需的权限
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ClassroomController : ControllerBase
    {
        private readonly IClassroomService _classroomService;

        public ClassroomController(IClassroomService classroomService)
        {
            _classroomService = classroomService;
        }

        /// <summary>
        /// 获取教室分页列表
        /// </summary>
        /// <param name="pageRequest">分页请求参数</param>
        /// <returns>教室分页列表</returns>
        [HttpPost]
        public async Task<ApiResponse<PagedResult<ClassroomDto>>> GetPagedList([FromBody] ClassroomPageRequest pageRequest)
        {
            var result = await _classroomService.GetPagedListAsync(pageRequest);
            return ApiResponse<PagedResult<ClassroomDto>>.Ok(result);

            //不想返回时间带T的格式
        }

        /// <summary>
        /// 获取教室详情
        /// </summary>
        /// <param name="request">ID请求参数</param>
        /// <returns>教室详情</returns>
        [HttpPost]
        public async Task<ApiResponse<ClassroomDto>> GetById([FromBody] IdRequest request)
        {
            var classroom = await _classroomService.GetByIdAsync(request.Id);
            return ApiResponse<ClassroomDto>.Ok(classroom);

        }

        /// <summary>
        /// 创建教室
        /// </summary>
        /// <param name="input">创建教室请求参数</param>
        /// <returns>教室详情</returns>
        [HttpPost]
        [RequirePermission("basic.classroom")] // 指定所需的权限
        public async Task<ApiResponse<ClassroomDto>> Create([FromBody] CreateClassroomDto input)
        {
            var classroom = await _classroomService.CreateAsync(input);
            return ApiResponse<ClassroomDto>.Ok(classroom);
        }

        /// <summary>
        /// 更新教室
        /// </summary>
        /// <param name="input">更新教室请求参数</param>
        /// <returns>教室详情</returns>
        [HttpPost]
        [RequirePermission("basic.classroom")] // 指定所需的权限
        public async Task<ApiResponse<ClassroomDto>> Update([FromBody] UpdateClassroomDto input)
        {
            var classroom = await _classroomService.UpdateAsync(input);
            return ApiResponse<ClassroomDto>.Ok(classroom);
        }

        /// <summary>
        /// 删除教室
        /// </summary>
        /// <param name="request">ID请求参数</param>
        [HttpPost]
        [RequirePermission("basic.classroom")] // 指定所需的权限
        public async Task<ApiResponse<object>> Delete([FromBody] IdRequest request)
        {
            await _classroomService.DeleteAsync(request.Id);
            return ApiResponse<object>.Ok(new object());
        }
    }
}